package com.yand.thinkingInJava.thinkingInJava21.threadNewcomponent;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DelayQueueTest {

    public static void main(String [] args){
        // 创建延时队列
        DelayQueue<Message> queue = new DelayQueue<Message>();
        // 添加延时消息,m1 延时5s
        Message m1 = new Message(1, "world", 3000);
        // 添加延时消息,m2 延时3s
        Message m2 = new Message(2, "hello", 1000);
        queue.offer(m2);
        queue.offer(m1);



        ExecutorService exec = Executors.newSingleThreadExecutor();
        exec.execute(new Consumer(queue));

        exec.shutdown();
    }
}
